<template>
  <div class="">
    <div class="radiobox">
      <div class="">
        <div class="card_label">
          <div v-if="requireFlag" class="require_icon">*</div>

          <div class="label_txt">{{ label }}：</div>
        </div>
        <div class="card_select">
          <div class="radio_item" v-for="(item, index) in list" :key="index" @click="handleSelectChange(index, item)">
            <img class="item_icon" :src="require(`@/assets/images/${active == index ? 'check' : 'nocheck'}.jpg`)" />
            <div class="item_name">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SelectRadio',
  components: {},
  props: {
    label: {
      type: String,
      default: null,
    },
    list: {
      type: Array,
      default: [],
    },
    field: {
      type: String,
      default: null,
    },

    requireFlag: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      active: null,
    }
  },
  watch: {
    list: {
      handler: function (val, oldVal) {
        console.log(val)
        if (val) {
          if (this.field == 'followType') {
            this.list &&
              this.list.forEach((item, index) => {
                if (item.value == 'phone') {
                  this.active = index
                  this.$emit('getFieldVal', this.field, item.value)
                }
              })
          }
        }
      },
      deep: true,
      immediate: false,
    },
  },

  mounted() {
    if (this.field == 'bookingType') {
      this.active = 0
      this.$emit('getFieldVal', this.field, 3)
    }
  },

  methods: {
    handleSelectChange(index, item) {
      this.active = index
      this.$emit('getFieldVal', this.field, item.value)
    },
  },
}
</script>

<style lang="less" scoped>
.followInfo {
  position: fixed;
  width: 100%;
  height: 70vh;
  overflow: auto;
  bottom: 0;
  left: 0;
  z-index: 10;
  box-shadow: 0px 1px 0px 0px rgba(40, 47, 56, 0.04);
  border-radius: 10px 10px 0px 0px;
  background: #fff;
  .followInfo_title {
    text-align: center;
    padding: 10px;
    border-bottom: 1px solid #f2f2f2;
  }
}
.radiobox {
  box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.02);
  border-radius: 4px 4px 4px 4px;
  border: 1px solid #f4f4f6;
  padding: 8px 17px 0px 17px;
  .card_label {
    display: flex;
    margin-bottom: 10px;
    .require_icon {
      font-weight: 400;
      font-size: 12px;
      color: #ff4848;
    }
    .label_txt {
      font-weight: 400;
      font-size: 12px;
      color: #86909c;
    }
  }
  .card_select {
    display: flex;
    flex-wrap: wrap;
    .radio_item {
      width: 33%;
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .item_icon {
        width: 18px;
        display: block;
        margin-right: 5px;
      }
      .item_name {
        font-weight: 600;
        font-size: 12px;
        color: #2f2f2f;
      }
    }
  }
}
</style>
